package org.xtext.runtime.formula;

import java.util.Map;
import java.util.Set;

import org.xtext.runtime.term.Variable;
import org.xtext.runtime.util.Bindings;
import org.xtext.runtime.util.ILogicVisitor;


public class MentalEvent implements Event {
	public static final char ADDITION						= '+';
	public static final char REMOVAL						= '-';
	
	protected char type;
	protected IFormula formula;
	private Object source;

	public MentalEvent(char type, IFormula formula) {
		this(type, formula, null);
	}
	
	public MentalEvent(char type, IFormula formula, Object source) {
		this.type = type;
		this.formula = formula;
		this.source = source;
	}
	
	public char type() {
		return type;
	}
	
	public IFormula formula() {
		return formula;
	}
	
	public String toString() {
		return "" + type + formula;
	}

	@Override
	public MentalEvent copy() {
		return new MentalEvent(type, formula.copy(), source);
	}
	
	public String signature() {
		if (Predicate.class.isInstance(formula)) {
			return type+((Predicate) formula).signature();
		} else if (Goal.class.isInstance(formula)) {
			return type+((Goal) formula).signature();
		}
		return "no signature";
	}

	@Override
	public Set<Variable> variables() {
		return formula.variables();
	}

	@Override
	public MentalEvent apply(Bindings bindings) {
		formula.apply(bindings);
		return this;
	}

	@Override
	public MentalEvent copy(Map<String, Variable> vars) {
		return new MentalEvent(type, formula.copy(vars), source);
	}

	public Object source() {
		return source;
	}

	@Override
	public boolean hasFreeVariables() {
		return formula.hasFreeVariables();
	}

	@Override
	public Object accept(ILogicVisitor visitor) {
		return null;
	}
}
